package cn.fy.springbootday1.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

@Configuration //声明一个类是一个Java配置类，相当于xml配置
//@PropertySource("classpath:jdbc.properties") //读取外部资源文件
//@EnableConfigurationProperties(JdbcProperties.class)
public class JdbcConfiguration {


//    @Autowired
//    private JdbcProperties jdbcProperties;


    @Bean //把方法的返回值注入spring容器
    @ConfigurationProperties(prefix = "jdbc")
    public DataSource dataSource() {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setUsername(this.jdbcProperties.getUsername());
//        dataSource.setUrl(this.jdbcProperties.getUrl());
//        dataSource.setPassword(this.jdbcProperties.getPassword());
//        dataSource.setDriverClassName(this.jdbcProperties.getDriverClassName());
        return new DruidDataSource();
    }
}
